package main

import (
	"awesomeProject/micro_demo/micro-02-service/proto"
	"fmt"
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/client/selector"
	"github.com/micro/go-micro/v2/registry"
	"github.com/micro/go-micro/v2/registry/etcd"
)

func main() {

	etcdr := etcd.NewRegistry(registry.Addrs("localhost:2379")) // 服务注册
	service := micro.NewService(
		micro.Name("service.user"),
		micro.Version("1.0.0"),
		micro.Registry(etcdr), //服务发现
	)

	//service.Init() //parses command line flags

	_ = proto.RegisterUserHandler(service.Server(), new(User))
	if err := service.Run(); err != nil {
		fmt.Println(err)
	}
	selector.NewSelector(
		selector.Registry(etcdr),
		selector.SetStrategy(selector.Random), //随机访问
	)

}

/*

etcdctl get / --prefix
查看注册到etcd 里面的服务


1、设置环境变量
export MICRO_REGISTRY=etcd
export MICRO_REGISTRY_ADDRESS=localhost:2379

2、输入
micro web 命令，可以启动一个web 来查看启动的service

*/
